#include "greppanel.h"
#include <QHBoxLayout>

GrepPanel::GrepPanel(QWidget *parent) :
    QWidget(parent)
{
    QHBoxLayout * layout = new QHBoxLayout;
    setLayout(layout);

    m_grepButton = new QPushButton("GREP");
    m_doneButton = new QPushButton("Done");

    m_pattern = new QLineEdit;
    layout->addWidget(m_pattern);
    layout->addWidget(m_grepButton);
    layout->addWidget(m_doneButton);

    connect(m_grepButton, SIGNAL(pressed()), this, SLOT(onGrepPressed()));
    connect(m_doneButton, SIGNAL(pressed()), this, SLOT(onDonePressed()));

    connect(m_pattern, SIGNAL(returnPressed()), m_grepButton, SLOT(click()));
}

GrepPanel::~GrepPanel()
{
    delete m_grepButton;
    delete m_doneButton;
    delete m_pattern;
}


void GrepPanel::onGrepPressed()
{
    if(m_pattern->text().length() > 0)
        emit grepStarted(m_pattern->text());
}

void GrepPanel::onDonePressed()
{
    emit donePressed();
}

void GrepPanel::setEditFocus()
{
    m_pattern->setFocus();
}
